Re: [SQL] indexes using datetime
От | Herouth Maoz |
---|---|
Тема | Re: [SQL] indexes using datetime |
Дата | |
Msg-id | l03130306b3f98cc074df@[147.233.159.109] обсуждение исходный текст |
Ответ на | Re: [SQL] indexes using datetime (Tom Lane <tgl@sss.pgh.pa.us>) |
Список | pgsql-sql |
At 03:46 +0300 on 29/08/1999, Tom Lane wrote: > Michael Richards <miker@scifair.acadiau.ca> writes: > > explain select * from logins where logintime>'now'::datetime-'40 > > days'::timespan; > > NOTICE: QUERY PLAN: > > Seq Scan on logins (cost=5839.78 rows=44958 width=44) > > > Very bad query plan :( > > Yah. It's got nothing to do with datetime though. Problem is that the > system can only make indexscans work with WHERE clauses of the form > "field op constant" (for "op"s related to the sort ordering of the > index of course). Your righthand side is not a constant. A tip: use SELECT 'now'::datetime - '40 days'::timespan; Get the result on your client side, say in a variable named $x, and use it in the "real" query: SELECT * FROM logins WHERE logintime > $x; (Actual embedding protocol depends, of course, on the language you use). Then it's a constant, as far as Postgres is concerned, and the time wasted for the small query is really not an issue. Herouth -- Herouth Maoz, Internet developer. Open University of Israel - Telem project http://telem.openu.ac.il/~herutma
В списке pgsql-sql по дате отправления: